function [ contrastIndex] = contrastBoxIndex(x, y, numContrastRegions, boxsize, imgSize)
%contrastBoxes 
%   contrast Boxes generates white outlines that outline the contrast
%   regions selected by a user
%
%   Inputs
%   ---------
%   x is the x cordinate of a user input for a contrast region
%
%   y is the y cordinate of a user input for a contrast region
%
%   numContrastRegions indicates the number of different coordinate pairs
%   that were generated from user input
%
%   boxsize is the size of the contrast region boxes
%
%   imgSize is the size of the image that the contrast regions were
%   selected on.
%
%   Outputs
%   ---------
%   contrastBoxes are the white box outlines of the contrast regions
%
%   index is the index of the pixels that make up the box.


% % The commented code below will make the contrast region blocks white
% % for i_region = 1 : numContrastRegions
% %     yrange = (x(i_region) - boxsize) : (x(i_region) + boxsize);
% %     xrange = (y(i_region) - boxsize) : (y(i_region) + boxsize);
% %     
% %     contrast_region_pix = zeros(length(xrange)*length(yrange),2);
% %     
% %     k = 1;
% %     for i = 1 : length(xrange)
% %         for j = 1 : length(yrange)
% %             contrast_region_pix(k,:) = [xrange(i) yrange(j)];
% %             k = k + 1;
% %         end
% %     end
% %     
% %     X_contrast_region = contrast_region_pix(:,1);
% %     Y_contrast_region = contrast_region_pix(:,2);
% %     
% %     index_set = sub2ind(size(handles.otherAvgIm),X_contrast_region,Y_contrast_region);
% %     
% %     handles.iContrastRegion = [handles.iContrastRegion index_set'];
% %     
% % end


for i_region = 1 : numContrastRegions
    yrange = (x(i_region) - boxsize) : (x(i_region) + boxsize);
    xrange = (y(i_region) - boxsize) : (y(i_region) + boxsize);
    
    contrast_region_pix = zeros(length(xrange)*length(yrange),2);
    pixcount = 0;
    
    %top/bottom
    for k = 1 : length(xrange)
        pixcount = pixcount + 1;
        contrast_region_pix(pixcount,:) = [xrange(k) yrange(1)];
        pixcount = pixcount + 1;
        contrast_region_pix(pixcount,:) = [xrange(k) yrange(2)];
        pixcount = pixcount + 1;
        contrast_region_pix(pixcount,:) = [xrange(k) yrange(end)];
        pixcount = pixcount + 1;
        contrast_region_pix(pixcount,:) = [xrange(k) yrange(end-1)];
    end
    
    %left/right
    for k = 1 : length(yrange)
        pixcount = pixcount + 1;
        contrast_region_pix(pixcount,:) = [xrange(1) yrange(k)];
        pixcount = pixcount + 1;
        contrast_region_pix(pixcount,:) = [xrange(2) yrange(k)];
        pixcount = pixcount + 1;
        contrast_region_pix(pixcount,:) = [xrange(end) yrange(k)];
        pixcount = pixcount + 1;
        contrast_region_pix(pixcount,:) = [xrange(end-1) yrange(k)];
    end
    
    contrast_region_pix(pixcount+1:end,:) = [];

    X_contrast_region = contrast_region_pix(:,1);
    Y_contrast_region = contrast_region_pix(:,2);
    
    contrastIndex = sub2ind(imgSize,X_contrast_region,Y_contrast_region);
   
end
end

